<?php

/**
 * model_student
 */

class Model_student extends YOU {

	public function __construct()
	{
		parent::__construct();

	}

	/** 读取总数 **/
	public function count()
	{
		$row = $this->db->fetchRow("SELECT COUNT(1) AS count FROM `tbl_student`");
		return (int)$row['count'];
	}

	/** 读取信息 **/
	public function getInfo($student_id, $field = "*")
	{
		$data = $this->db->fetchRow("SELECT {$field} FROM `tbl_student` WHERE student_id='{$student_id}' ");

		return $data;
	}
	
	/** 读取名称根据id **/
	public function getNameById($student_id)
	{
		$data = $this->getInfo($student_id, "student_name");

		return $data['student_name'];
	}	
	
	/** 根据班级----读取信息 **/
	public function getInfoclass($class_id, $field = "*")
	{
		$data = $this->db->fetchAll("SELECT {$field} FROM `tbl_student` WHERE class_id='{$class_id}' ");

		return $data;
	}

	/** 根据姓名 学号得到数据 **/
	public function getInfoByNo($student_no, $student_name = "")
	{
		$where = "";
		if (!empty($student_name)){
			$where .= " AND student_name='{$student_name}' ";
		}

		$data = $this->db->fetchRow("SELECT * FROM `tbl_student` WHERE student_no='{$student_no}' {$where} ");

		return $data;
	}
	/** 根据姓名 学籍号得到数据 **/
	public function getInfoBySC($student_school = '', $student_name = "")
	{
		
		$where = "";
		if (!empty($student_name)){
			$where .= " AND student_name='{$student_name}' ";
			
		}
		if (!empty($student_school)){
			$where .= " AND student_school='{$student_school}' ";
			
		}

		$data = $this->db->fetchRow("SELECT * FROM `tbl_student` WHERE student_school='{$student_school}' {$where} ");

		return $data;
	}
	/** 读取学生班干部信息 **/
	public function getAppInfo($leader_id, $field = "*")
	{
		$data = $this->db->fetchRow("SELECT {$field} FROM `tbl_student_leader` WHERE leader_id='{$leader_id}' ");

		return $data;
	}
	/** 读取学生班干部所有信息 **/
	public function getAppAll( $field = "*")
	{
		$data = $this->db->fetchAll("SELECT {$field} FROM `tbl_student_leader` ");

		return $data;
	}
	/** 班级id-》读取信息 **/
	public function getClassInfo($class_id, $field = "*")
	{
		$data = $this->db->fetchRow("SELECT {$field} FROM `tbl_student` WHERE class_id='{$class_id}' ");

		return $data;
	}
	/** 班级id-》读取信息 **/
	public function getClassAll($class_id, $field = "*")
	{
		$lists = $this->db->fetchAll("SELECT {$field} FROM `tbl_student` WHERE class_id='{$class_id}' ");

		return $lists;
	}
	/** 读取调班全部信息 **/
	public function getDivide($field = "*")
	{
		$divide_lists = $this->db->fetchAll("SELECT {$field} FROM `tbl_student_divide");

		return $divide_lists;
	}
	/** 根据id获取班主任 **/
	public function getTeacher($student_id, $field = "*")
	{
		
		$data = $this->db->fetchRow("SELECT {$field} FROM `tbl_student` WHERE student_id ='{$student_id}'" );
		
		$data = $this->db->fetchRow("SELECT {$field} FROM `tbl_appoint` WHERE class_id='{$data['class_id']}'" );
		$data = $this->db->fetchRow("SELECT `staff_id`,`staff_name` FROM `tbl_staff` WHERE staff_id='{$data['staff_id']}'" );

		return $data;
	}
	/** 根据名字模糊搜索 **/
	public function getName($student_name, $field = "*")
	{
		$student_lists = $this->db->fetchAll("SELECT {$field} FROM `tbl_student` WHERE student_name LIKE '%{$student_name}%'");

		return $student_lists;
	}
	
	
}



?>